home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / SYS / AMIGA / TTYMENU.C < prev    next >
C/C++ Source or Header  |  1988-08-23  |  17KB  |  619 lines

  1. /*
  2.  * ttymenu.c
  3.  *
  4.  * Incorporates the browser, for rummaging around on disks,
  5.  * and the usual Emacs editing command menu
  6.  *
  7.  *    Copyright (c) 1986, Mike Meyer
  8.  *    Mic Kaczmarczik did a few things along the way.
  9.  *
  10.  * Permission is hereby granted to distribute this program, so long as
  11.  * this source file is distributed with it, and this copyright notice
  12.  * is not removed from the file.
  13.  *
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <libraries/dos.h>
  18. #include <libraries/dosextens.h>
  19. #include <intuition/intuition.h>
  20. #undef    TRUE
  21. #undef    FALSE
  22. #include "def.h"
  23. #ifndef    NO_MACRO
  24. #include "macro.h"
  25. #endif    
  26.  
  27. extern struct Menu        *AutoMenu ;
  28. extern struct Window        *EmW ;
  29.  
  30. #ifdef    LATTICE
  31. static VOID    Add_Devices(ULONG) ;
  32. #else
  33. static VOID    Add_Devices() ;
  34. #endif
  35.  
  36. #define MNUM(menu,item,sub) (SHIFTMENU(menu)|SHIFTITEM(item)|SHIFTSUB(sub))
  37.  
  38. #ifdef    BROWSER
  39. #define LONGEST_NAME    80    /* Longest file name we can deal with    */
  40.  
  41. # ifdef    LATTICE
  42. char *strchr(char *, int);
  43. # else
  44. char *index();            /* find first instance of c in s    */
  45. #define    strchr(s, c) index(s, c)
  46. # endif
  47.  
  48. # ifdef    MENU
  49. #define    FIRSTMENU    1
  50. # else
  51. #define    FIRSTMENU    0
  52. # endif
  53.  
  54. #endif    BROWSER
  55.  
  56. #ifdef    MENU
  57. /*
  58.  * When ttgetc() sees a menu selection event, it stuffs the sequence
  59.  * KMENU <menu><item><subitem> into the input buffer
  60.  *
  61.  * The menu item names are chosen to be relatively close to the extended
  62.  * function names, so a user can usually figure out the key binding of
  63.  * a menu item by searching through the "display-bindings" buffer
  64.  * for something that's close.
  65.  */
  66.  
  67. /*
  68.  * Commands for managing files and buffers
  69.  */
  70.  
  71. extern    int    filevisit();
  72. extern    int    poptofile();
  73. extern    int    fileinsert();
  74. extern    int    filesave();
  75. extern    int    filewrite();
  76. #ifndef    NO_DIRED
  77. extern    int    dired();
  78. #endif
  79. extern    int    usebuffer();
  80. extern    int    poptobuffer();
  81. extern    int    killbuffer();
  82. extern    int    listbuffers();
  83. extern    int    savebuffers();
  84. extern    int    quit();
  85.  
  86. static struct MenuBinding FileItems[] = {
  87.     { "Find File         C-x C-f",    filevisit    },
  88.     { "Pop To File       C-x 4 f",    poptofile    },
  89.     { "Insert File       C-x i",    fileinsert    },
  90.     { "Save File         C-x C-s",    filesave    },
  91.     { "Write File        C-x C-w",    filewrite    },
  92. #ifndef    NO_DIRED
  93.     { "Dired         C-x d",    dired        },
  94. #endif
  95.     { "Switch To Buffer  C-x b",    usebuffer    },
  96.     { "Pop To Buffer     C-x 4 b",    poptobuffer    },
  97.     { "Kill Buffer       C-x k",    killbuffer    },
  98.     { "List Buffers      C-x C-b",    listbuffers    },
  99.     { "Save Buffers      C-x s",    savebuffers    },
  100.     { "Save And Exit     C-x C-c",    quit        }
  101. };
  102.  
  103. /*
  104.  * Commands for various editing functions
  105.  */
  106.  
  107. extern    int    yank();
  108. extern    int    openline();
  109. extern    int    killline();
  110. extern    int    deblank();
  111. extern    int    justone();
  112. extern    int    indent();
  113. extern    int    twiddle();
  114. extern    int    quote();
  115.  
  116. static struct MenuBinding EditItems[] = {
  117.     { "Yank                 C-y",    yank        },
  118.     { "Blank Line           C-o ",    openline    },
  119.     { "Kill Line            C-k",    killline    },
  120.     { "Delete Blank Lines   C-x C-o",deblank    },
  121.     { "Delete Blanks        M-SPC",    justone        },
  122.     { "Newline And Indent   C-j",    indent        },
  123.     { "Transpose Characters C-t",    twiddle        },
  124.     { "Quoted Insert        C-q",    quote        }
  125. };
  126.  
  127. /*
  128.  * Movement commands
  129.  */
  130.  
  131. extern    int    forwpage();
  132. extern    int    backpage();
  133. extern    int    gotobol();
  134. extern    int    gotobob();
  135. extern    int    gotoeol();
  136. extern    int    gotoeob();
  137. extern    int    gotoline();
  138. extern    int    showcpos();
  139.  
  140. static struct MenuBinding MoveItems[] = {
  141.     { "Scroll Up       C-v",    forwpage    },
  142.     { "Scroll Down     M-v",    backpage    },
  143.     { "Start Of Line   C-a",    gotobol        },
  144.     { "Start Of Buffer M-<",    gotobob        },
  145.     { "End Of Line     C-e",    gotoeol        },
  146.     { "End Of Buffer   M->",    gotoeob        },
  147.     { "Goto Line",            gotoline    },
  148.     { "Show Cursor     C-x =",    showcpos    }
  149. };
  150.  
  151. /*
  152.  * Commands for searching and replacing
  153.  */
  154.  
  155. extern    int    forwisearch();
  156. extern    int    backisearch();
  157. extern    int    searchagain();
  158. extern    int    forwsearch();
  159. extern    int    backsearch();
  160. extern    int    queryrepl();
  161.  
  162. static struct MenuBinding SearchItems[] = {
  163.     { "I-Search Forward  C-s",    forwisearch    },
  164.     { "I-Search Backward C-r",    backisearch    },
  165.     { "Search Again",        searchagain    },
  166.     { "Search Forward    M-s",    forwsearch    },
  167.     { "Search Backward   M-r",    backsearch    },
  168.     { "Query Replace     M-%",    queryrepl    }
  169. };
  170.  
  171. /*
  172.  * Commands that manipulate words
  173.  */
  174. extern    int    forwword();
  175. extern    int    backword();
  176. extern    int    delfword();
  177. extern    int    delbword ();
  178. extern    int    capword();
  179. extern    int    lowerword();
  180. extern    int    upperword();
  181.  
  182. static struct MenuBinding WordItems[] = {
  183.     { "Forward Word       M-f",    forwword    },
  184.     { "Backward Word      M-b",    backword    },
  185.     { "Kill Word          M-d",    delfword    },
  186.     { "Backward Kill Word M-DEL",    delbword     },
  187.     { "Capitalize Word    M-c",    capword        },
  188.     { "Downcase Word      M-l",    lowerword    },
  189.     { "Upcase Word        M-u",    upperword    }
  190. };
  191.  
  192. /*
  193.  * Commands relating to paragraphs
  194.  */
  195. extern    int    gotoeop();
  196. extern    int    gotobop();
  197. extern    int    fillpara();
  198. extern    int    setfillcol();
  199. extern    int    killpara();
  200. extern    int    fillmode();
  201.  
  202. static struct MenuBinding ParaItems[] = {
  203.     { "Forward Paragraph  M-]",    gotoeop        },
  204.     { "Backward Paragraph M-[",    gotobop        },
  205.     { "Fill Paragraph     M-q",    fillpara    },
  206.     { "Set Fill Column    C-x f",    setfillcol    },
  207.     { "Kill Paragraph",        killpara    },
  208.     { "Auto Fill Mode",        fillmode    }
  209. };
  210.  
  211. /*
  212.  * Region stuff
  213.  */
  214. extern    int    setmark();
  215. extern    int    swapmark();
  216. extern    int    killregion();
  217. extern    int    copyregion();
  218. extern    int    lowerregion();
  219. extern    int    upperregion();
  220.  
  221. static struct MenuBinding RegionItems[] = {
  222.     { "Set Mark            C-@",    setmark        },
  223.     { "Exch Point And Mark C-x C-x",swapmark    },
  224.     { "Kill Region         C-w",    killregion    },
  225.     { "Copy Region As Kill M-w",    copyregion    },
  226.     { "Downcase Region     C-x C-l",lowerregion    },
  227.     { "Upcase Region       C-x C-u",upperregion    }
  228. };
  229.  
  230. /*
  231.  * Commands for manipulating windows
  232.  */
  233.  
  234. extern    int    splitwind();
  235. extern    int    delwind();
  236. extern    int    onlywind();
  237. extern    int    nextwind();
  238. #ifdef    PREVWIND
  239. extern    int    prevwind();
  240. #endif
  241. extern    int    enlargewind();
  242. extern    int    shrinkwind();
  243. extern    int    refresh();
  244. extern    int    reposition();
  245. extern    int    togglewindow();
  246. #ifdef    CHANGE_FONT
  247. extern    int    setfont();
  248. #endif
  249.  
  250. static struct MenuBinding WindowItems[] = {
  251.     { "Split Window         C-x 2", splitwind    },
  252.     { "Delete Window        C-x 0",    delwind        },
  253.     { "Delete Other Windows C-x 1",    onlywind    },
  254.     { "Next Window          C-x o",    nextwind    },
  255. #ifdef    PREVWIND
  256.     { "Up Window",            prevwind    },
  257. #endif
  258.     { "Enlarge Window       C-x ^",    enlargewind    },
  259.     { "Shrink Window",        shrinkwind    },
  260.     { "Redraw Display",        refresh        },
  261.     { "Recenter             C-l",    reposition    },
  262.     { "Toggle Border",        togglewindow    },
  263. #ifdef    CHANGE_FONT
  264.     { "Set Font",            setfont        }
  265. #endif
  266. };
  267.  
  268. /*
  269.  * Miscellaneous commands
  270.  */
  271.  
  272. extern    int    definemacro();
  273. extern    int    finishmacro();
  274. extern    int    executemacro();
  275. extern    int    extend();
  276. extern    int    bindtokey();
  277. extern    int    desckey();
  278. extern    int    wallchart();
  279. extern    int    showversion();
  280. extern    int    spawncli();
  281.  
  282. static struct MenuBinding MiscItems[] = {
  283.     { "Start Kbd Macro   C-x (",    definemacro    },
  284.     { "End Kbd Macro     C-x )",    finishmacro    },
  285.     { "Call Kbd Macro    C-x e",    executemacro    },
  286.     { "Execute Command   M-x",    extend        },
  287.     { "Global Set Key",        bindtokey    },
  288.     { "Describe Key      C-h c",    desckey        },
  289.     { "Describe Bindings C-h b",    wallchart    },
  290.     { "Emacs Version",        showversion    },
  291.     { "New CLI           C-z",    spawncli    }
  292. };
  293.  
  294. /*
  295.  * The following table contains the titles, number of items, and
  296.  * pointers to, the individual menus.
  297.  */
  298.  
  299. static struct MenuInfo EMInfo[] = {
  300.     { "File  ",        NITEMS(FileItems),    &FileItems[0]    },
  301.     { "Edit  ",        NITEMS(EditItems),    &EditItems[0]    },
  302.     { "Move  ",         NITEMS(MoveItems),    &MoveItems[0]    },
  303.     { "Search  ",        NITEMS(SearchItems),    &SearchItems[0] },
  304.     { "Word  ",        NITEMS(WordItems),    &WordItems[0]    },
  305.     { "Paragraph  ",    NITEMS(ParaItems),    &ParaItems[0]    },
  306.     { "Region  ",        NITEMS(RegionItems),    &RegionItems[0]    },
  307.     { "Window  ",        NITEMS(WindowItems),    &WindowItems[0] },
  308.     { "Miscellaneous  ",    NITEMS(MiscItems),    &MiscItems[0]    }
  309. };
  310.  
  311. /* There are three cases to deal with; the menu alone, the